const music = {
	instance: null,
	bgmInstance: null,
	play_bgm(){
		if(this.bgmInstance == null){
			this.bgmInstance = uni.createInnerAudioContext();
			// this.bgmInstance = tt.createInnerAudioContext();
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.bgm){
				this.bgmInstance.volume = 0;
			}else{
				this.bgmInstance.volume = uni.getStorageSync('volume')!==''?uni.getStorageSync('volume'):0.6;
			}
			this.bgmInstance.autoplay = true;
			this.bgmInstance.loop = true;
			this.bgmInstance.src = 'https://siha.vxmeng.com/static/video/' + 'bgm.mp3';
			this.bgmInstance.onPlay(() => {
				console.log('开始播放');
			});
			this.bgmInstance.onPause(() => {
				console.log('暂停播放');
			});
			this.bgmInstance.onError((res) => {
				console.log('播放错误'+res.errMsg);
			});
		}else{
			return
		}
	},
	play_click_1() {
		if (this.instance == null) {
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.btn){
				return
			}
			this.instance = uni.createInnerAudioContext();
			this.instance.volume = uni.getStorageSync('volume');
			this.instance.src = 'https://siha.vxmeng.com/static/video/' + 'click-1.mp3';
			this.instance.play();

			this.instance.onEnded(() => {
				this.instance.destroy();
				this.instance = null;
			});
		} else {
			return;
		}
	},
	play_click_2() {
		if (this.instance == null) {
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.btn){
				return
			}
			this.instance = uni.createInnerAudioContext();
			this.instance.volume = uni.getStorageSync('volume');
			this.instance.src = 'https://siha.vxmeng.com/static/video/' + 'click-2.mp3';
			this.instance.play();

			this.instance.onEnded(() => {
				this.instance.destroy();
				this.instance = null;
			});
		} else {
			return;
		}
	},
	play_confirm(){
		if (this.instance == null) {
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.btn){
				return
			}
			this.instance = uni.createInnerAudioContext();
			this.instance.volume = uni.getStorageSync('volume');
			this.instance.autoplay = true;
			this.instance.src = 'https://siha.vxmeng.com/static/video/' + 'confirm.wav';
		
			this.instance.onEnded(() => {
				this.instance.destroy();
				this.instance = null;
			});
		} else {
			return;
		}
	},
	play_confirm_2(){
		if (this.instance == null) {
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.btn){
				return
			}
			this.instance = uni.createInnerAudioContext();
			this.instance.volume = uni.getStorageSync('volume');
			this.instance.autoplay = true;
			this.instance.src = 'https://siha.vxmeng.com/static/video/' + 'confirm-2.wav';
		
			this.instance.onEnded(() => {
				this.instance.destroy();
				this.instance = null;
			});
		} else {
			return;
		}
	},
	play_error(){
		if (this.instance == null) {
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.btn){
				return
			}
			this.instance = uni.createInnerAudioContext();
			this.instance.volume = uni.getStorageSync('volume');
			this.instance.autoplay = true;
			this.instance.src = 'https://siha.vxmeng.com/static/video/' + 'error.wav';
		
			this.instance.onEnded(() => {
				this.instance.destroy();
				this.instance = null;
			});
		} else {
			return;
		}
	},
	play_obtain(){
		if (this.instance == null) {
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.btn){
				return
			}
			this.instance = uni.createInnerAudioContext();
			this.instance.volume = uni.getStorageSync('volume');
			this.instance.autoplay = true;
			this.instance.src = 'https://siha.vxmeng.com/static/video/' + 'obtain.wav';
		
			this.instance.onEnded(() => {
				this.instance.destroy();
				this.instance = null;
			});
		} else {
			return;
		}
	},
	play_return(){
		if (this.instance == null) {
			const state = JSON.parse(uni.getStorageSync('volumeState') || '{"muted": false,"bgm": true,"btn": true}');
			if(state.muted || !state.btn){
				return
			}
			this.instance = uni.createInnerAudioContext();
			this.instance.volume = uni.getStorageSync('volume');
			this.instance.autoplay = true;
			this.instance.src = 'https://siha.vxmeng.com/static/video/' + 'return.wav';
		
			this.instance.onEnded(() => {
				this.instance.destroy();
				this.instance = null;
			});
		} else {
			return;
		}
	},
}

module.exports = music;